package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.*;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberVisitListResponse;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberVisitTypeItemResponse;
import com.ssy.lingxi.member.merchant.model.vo.validate.response.MemberClassifyCategoryItemVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberVisitService;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 会员能力 - 会员拜访相关接口
 * @author hkm
 * @version 2.0.0
 * @date 2020-09-07
 */
@RestController
@RequestMapping("/member/visit")
public class MemberVisitController extends BaseController {
    @Resource
    private IMemberVisitService memberVisitService;

    /**
     * 查询会员拜访列表
     * @param request
     * @return
     */
    @GetMapping("/list")
    public Wrapper<PageData<MemberVisitListResponse>> memberVisitList(MemberVisitListRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return memberVisitService.memberVisitList(request,sysUser);
    }

    /**
     * 查询会员拜访详情
     * @param id
     * @return
     */
    @GetMapping("/details")
    public Wrapper<MemberVisitListResponse> memberVisitDetails(Long id) {
        return memberVisitService.memberVisitDetails(id);
    }

    /**
     * 查询全部会员拜访
     * @param httpServletRequest
     * @return
     */
    @GetMapping("/all")
    public Wrapper<List<MemberVisitListResponse>> memberVisitAll(HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return memberVisitService.memberVisitAll(sysUser);
    }

    /**
     * 添加/修改会员拜访
     * @param request
     * @return
     */
    @PostMapping("/addOrUpdate")
    public Wrapper<Void> memberVisitAddOrUpdate(@RequestBody @Valid MemberVisitAddOrUpdateRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return memberVisitService.memberVisitAddOrUpdate(request,sysUser);
    }

    /**
     * 删除会员拜访
     * @return
     */
    @PostMapping("/delete")
    public Wrapper<Void> memberVisitDelete(@RequestBody @Validated CommonIdRequest request) {
        return memberVisitService.memberVisitDelete(request);
    }

    /**
     * 查询拜访类型, 拜访级别枚举
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/visitType/items", method = RequestMethod.GET)
    public Wrapper<MemberVisitTypeItemResponse> getMemberVisitOfVisitTypeItems(@RequestHeader HttpHeaders headers) {
        return memberVisitService.getMemberVisitOfVisitTypeItems(headers);
    }

}
